package com.ruoyi.project.registration.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.registration.domain.RegPatient;
import com.ruoyi.project.registration.service.RegPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/registration/regPatient")
public class RegPatientController extends BaseController {
    @Autowired
    private RegPatientService regPatientService;

    /**
     * 新增患者
     */
    @PreAuthorize("@ss.hasPermi('registration:regPatient:add')")
    @Log(title = "看病就诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addRegPatient(@RequestBody RegPatient regPatient){
        regPatient.setCreateBy(SecurityUtils.getUsername());
        int rows = regPatientService.insertRegPatient(regPatient);
        return toAjax(rows);
    }


    /**
     * 主键查询
     */
    @GetMapping("/{rpPid}")
    @PreAuthorize("@ss.hasPermi('registration:regPatient:query')")
    public AjaxResult getById(@PathVariable Integer rpPid){
        RegPatient regPatient = regPatientService.getByRpPid(rpPid);
        return AjaxResult.success(regPatient);
    }

    /**
     * 多条件查询
     * */
    @PreAuthorize("@ss.hasPermi('registration:regPatient:query')")
    @GetMapping("/list")
    public TableDataInfo list(RegPatient regPatient){
        // 分页相关,处理请求参数pageNum，pageSize等。并使用PageHelper处理分页查询。
        startPage();

        // 调用service查询数据库
        List<RegPatient> list = regPatientService.selectList(regPatient);

        // 返回
        return getDataTable(list);
    }
}
